using System.Collections.Generic;
using UnityEngine;

[ExecuteInEditMode]
public class Editbuild : MonoBehaviour
{
	public DataController alldata;

	public List<Transform> roots;

	public List<Transform> roots_fri;

	public bool issea;

	public bool isrunflag;

	public List<Transform> roots_ship;

	public List<Transform> roots_ship_fri;

	private NPC_ID_num tempnpc;

	private PosRot temppr;

	public Transform root_start;

	private int posnum;

	private void Update()
	{
		if (isrunflag)
		{
			alldata = GameObject.Find("DataController").GetComponent<DataController>();
			isrunflag = false;
			if (issea)
			{
				readinfo_sea();
				readinfo_fri_sea();
				readinfo_sea_ship();
				readinfo_sea_ship_fri();
			}
			else
			{
				readAIstartpos();
			}
		}
	}

	public void readAIstartpos()
	{
		alldata.AIStartPos.Clear();
		foreach (Transform item in root_start)
		{
			temppr = null;
			temppr = new PosRot();
			temppr.pos = item.position;
			temppr.rot = item.transform.eulerAngles;
			alldata.AIStartPos.Add(temppr);
		}
	}

	public void readinfo()
	{
		alldata.DataBuild_AI.Clear();
		alldata.DataBuild_AI = new List<NPC_ID_num>();
		for (int i = 0; i < roots.Count; i++)
		{
			posnum = 0;
			tempnpc = null;
			tempnpc = new NPC_ID_num();
			tempnpc.ID = i;
			tempnpc.pos_rot.Clear();
			tempnpc.pos_rot = new List<PosRot>();
			foreach (Transform item in roots[i])
			{
				temppr = null;
				temppr = new PosRot();
				temppr.pos = item.position;
				temppr.rot = item.transform.eulerAngles;
				tempnpc.pos_rot.Add(temppr);
				posnum++;
			}
			if (posnum != 0)
			{
				tempnpc.num = posnum;
				alldata.DataBuild_AI.Add(tempnpc);
			}
		}
	}

	public void readinfo_fri()
	{
		alldata.DataBuild_Fri.Clear();
		alldata.DataBuild_Fri = new List<NPC_ID_num>();
		for (int i = 0; i < roots_fri.Count; i++)
		{
			posnum = 0;
			tempnpc = null;
			tempnpc = new NPC_ID_num();
			tempnpc.ID = i;
			tempnpc.pos_rot.Clear();
			tempnpc.pos_rot = new List<PosRot>();
			foreach (Transform item in roots_fri[i])
			{
				temppr = null;
				temppr = new PosRot();
				temppr.pos = item.position;
				temppr.rot = item.transform.eulerAngles;
				tempnpc.pos_rot.Add(temppr);
				posnum++;
			}
			if (posnum != 0)
			{
				tempnpc.num = posnum;
				alldata.DataBuild_Fri.Add(tempnpc);
			}
		}
	}

	public void readinfo_sea()
	{
		alldata.DataBuild_AI_sea.Clear();
		alldata.DataBuild_AI_sea = new List<NPC_ID_num>();
		for (int i = 0; i < roots.Count; i++)
		{
			posnum = 0;
			tempnpc = null;
			tempnpc = new NPC_ID_num();
			tempnpc.ID = i;
			tempnpc.pos_rot.Clear();
			tempnpc.pos_rot = new List<PosRot>();
			foreach (Transform item in roots[i])
			{
				temppr = null;
				temppr = new PosRot();
				temppr.pos = item.position;
				temppr.rot = item.transform.eulerAngles;
				tempnpc.pos_rot.Add(temppr);
				posnum++;
			}
			if (posnum != 0)
			{
				tempnpc.num = posnum;
				alldata.DataBuild_AI_sea.Add(tempnpc);
			}
		}
	}

	public void readinfo_fri_sea()
	{
		alldata.DataBuild_Fri_sea.Clear();
		alldata.DataBuild_Fri_sea = new List<NPC_ID_num>();
		for (int i = 0; i < roots_fri.Count; i++)
		{
			posnum = 0;
			tempnpc = null;
			tempnpc = new NPC_ID_num();
			tempnpc.ID = i;
			tempnpc.pos_rot.Clear();
			tempnpc.pos_rot = new List<PosRot>();
			foreach (Transform item in roots_fri[i])
			{
				temppr = null;
				temppr = new PosRot();
				temppr.pos = item.position;
				temppr.rot = item.transform.eulerAngles;
				tempnpc.pos_rot.Add(temppr);
				posnum++;
			}
			if (posnum != 0)
			{
				tempnpc.num = posnum;
				alldata.DataBuild_Fri_sea.Add(tempnpc);
			}
		}
	}

	public void readinfo_sea_ship()
	{
		alldata.sea_ship_AI.Clear();
		alldata.sea_ship_AI = new List<NPC_ID_num>();
		for (int i = 0; i < roots_ship.Count; i++)
		{
			posnum = 0;
			tempnpc = null;
			tempnpc = new NPC_ID_num();
			tempnpc.ID = i;
			tempnpc.pos_rot.Clear();
			tempnpc.pos_rot = new List<PosRot>();
			foreach (Transform item in roots_ship[i])
			{
				temppr = null;
				temppr = new PosRot();
				temppr.pos = item.position;
				temppr.rot = item.transform.eulerAngles;
				tempnpc.pos_rot.Add(temppr);
				posnum++;
			}
			if (posnum != 0)
			{
				tempnpc.num = posnum;
				alldata.sea_ship_AI.Add(tempnpc);
			}
		}
	}

	public void readinfo_sea_ship_fri()
	{
		alldata.sea_ship_Fri.Clear();
		alldata.sea_ship_Fri = new List<NPC_ID_num>();
		for (int i = 0; i < roots_ship_fri.Count; i++)
		{
			posnum = 0;
			tempnpc = null;
			tempnpc = new NPC_ID_num();
			tempnpc.ID = i;
			tempnpc.pos_rot.Clear();
			tempnpc.pos_rot = new List<PosRot>();
			foreach (Transform item in roots_ship_fri[i])
			{
				temppr = null;
				temppr = new PosRot();
				temppr.pos = item.position;
				temppr.rot = item.transform.eulerAngles;
				tempnpc.pos_rot.Add(temppr);
				posnum++;
			}
			if (posnum != 0)
			{
				tempnpc.num = posnum;
				alldata.sea_ship_Fri.Add(tempnpc);
			}
		}
	}
}
